
// 富文本编辑器找到本地所有的img标签(base的转换为文件,外链除过img.wuqin6688.com)
export function findOuterImg(detail) {
  let contentImg = []
  // 1.所有img标签的src
  detail.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/g, function (match, capture) {
    contentImg.push(capture)
  })
  // 2.除去sinajs表情包的上传和wuqin6688图片上传
  contentImg = contentImg.filter(v => {
    return v.indexOf('sinajs') == -1
  })
  // 3.除去wuqin6688图片上传
  contentImg = contentImg.filter(v => {
    return v.indexOf('wuqin6688') == -1
  })

  return contentImg
}

// 将上传后的图片替换出路径(除了表情包和wuqin6688图片)
export function replaceImg(detail, replaceArrUrl) {
  var contentImg = []
  detail.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/g, function (match, capture) {
    contentImg.push(capture)
  })
  // 2.除去sinajs表情包的上传和wuqin6688图片上传
  contentImg = contentImg.filter(v => {
    return v.indexOf('sinajs') == -1
  })
  // 3.除去wuqin6688图片上传
  contentImg = contentImg.filter(v => {
    return v.indexOf('wuqin6688') == -1
  })

  if (contentImg.length > 0) {
    // 开始替换图片url
    for (var i = 0; i < contentImg.length; i++) {
      detail = detail.replace(contentImg[i], replaceArrUrl[i])
    }
  }
  console.log(detail, 'detaildetail')
  return detail
}
